package com.lanmaoly.cunzheng.weather2;

import com.lanmaoly.cunzheng.weather.DisplayElement;

import java.util.Observable;
import java.util.Observer;

public class ConditionsDisplay implements Observer, DisplayElement {

    private float a;
    private float b;
    private float c;
    private Observable observable;

    public ConditionsDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("温度:" + a + "湿度:" + b + "气温:" + c);
    }

    @Override
    public void update(Observable obs, Object arg) {
        if (obs instanceof WeatherData) {
            WeatherData weatherData = (WeatherData)obs;
            this.a = weatherData.getA();
            this.b = weatherData.getB();
            this.c = weatherData.getC();
            display();
        }
    }
}
